﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MK.oDataConsuming.ConsoleApp.CarServiceReference;

namespace MK.oDataConsuming.ConsoleApp {
    internal static class DataServiceConnectionController {

        #region Members
        private static CarContext context = new CarServiceReference.CarContext(new Uri("http://localhost.:1184/CarService.svc"));
        #endregion

        #region Methods
        internal static void Create(Car car) {
            
            //CarContext context = new CarServiceReference.CarContext(serviceUri);
            context.AddToCars(car);
            context.SaveChanges();
        }

        internal static void Delete(Car car) {

            //CarContext context = new CarServiceReference.CarContext(serviceUri);
            context.DeleteObject(car);
            context.SaveChanges();
        }

        internal static List<Car> RetrieveMultiple(/*Add query logic here*/) {

            //CarContext context = new CarServiceReference.CarContext(serviceUri);
            //var query = context.Cars.Where(c => c.Manufacturer == "Opel"); //Example with filter
            var query = context.Cars;
            List<Car> resultSet = query.ToList();
            return resultSet;
        }
        #endregion
    }
}
